package com.wanpinghui.supplier.user.company.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.wphlibrary.model.user.bean.CourseBean;
import com.yunshl.yunshllibrary.recyclerview.BaseRecyclerViewAdapter;
import com.yunshl.yunshllibrary.utils.TimeUtil;

/**
 * Created by tg596 on 2018/1/30.
 */

public class DevelopmentPathAdapter extends BaseRecyclerViewAdapter<CourseBean, DevelopmentPathAdapter.DevelopmentPathViewHolder> {


    private boolean isEdit;


    public DevelopmentPathAdapter(Context context) {
        super(context);
    }

    @Override
    public DevelopmentPathViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_developmentpath, parent, false);
        return new DevelopmentPathViewHolder(view);
    }

    @Override
    public void onBindViewHolder(DevelopmentPathViewHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        if (isEdit()){
            holder.mViewLine.setVisibility(View.VISIBLE);
            holder.mIvDelete.setVisibility(View.VISIBLE);
        }
        CourseBean bean = datas.get(position);
        holder.mTvTime.setText(TimeUtil.format(bean.getCourse_date()*1000, "yyyy-MM-dd"));
        holder.mTvContent.setText(bean.getCourse_content());
        holder.mIvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                datas.remove(position);
                notifyDataSetChanged();
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0:datas.size();
    }

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    class DevelopmentPathViewHolder extends RecyclerView.ViewHolder {

        View view;
        TextView mTvTime;
        TextView mTvContent;
        ImageView mIvDelete;
        View mViewLine;


        public DevelopmentPathViewHolder(View itemView) {
            super(itemView);
            this.view = itemView;
            this.mTvTime = (TextView) view.findViewById(R.id.tv_time);
            this.mTvContent = (TextView) view.findViewById(R.id.tv_content);
            this.mIvDelete = (ImageView) view.findViewById(R.id.iv_delete);
            this.mViewLine = view.findViewById(R.id.view_line);
        }
    }


}
